<?php

require_once __DIR__ . '/../includes/common.php';
use Backuper\Services\SvnBackup;
use Backuper\Services\DatabaseBackup;

function initZend($opts){
    
    $environment = $opts->getOption('env');
    define('APPLICATION_ENV', empty($environment) ? 'production' : $environment);

    // Define path to application directory
    defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', BASE_PATH . '/application/');
    
   
    // Create application, bootstrap
    $application = new Zend_Application(
        APPLICATION_ENV,
        APPLICATION_PATH . '/configs/application.ini'
    );
    $application->bootstrap();
    
}


$opts = new Zend_Console_Getopt(
  array(
      /*
    'svnuser-s' => 'Specify SVN user',
    'svnpwd-s' => 'Specify SVN password',
    'svnrepo=s'    => 'Required SVN repository URL or path',
    'db-s' => 'Specify the database name you want to backup, if no specification all databases will be backed up',
    'dbuser=s' => 'Specify database username',
    'dbpwd-s' => 'Specify database password',
    'dbserver=s' => 'Specify database server' */
    'env|e=-s' => 'Environment',
    'svn|s' => 'back up svn repositories',
    'database|d' => 'bacup database'
    
  )
);

try{
    
    $opts->parse();
    initZend($opts);
    
    $isSvnBackup = $opts->getOption('svn');
    
    if(!empty($isSvnBackup)){
        $svnbackup = new SvnBackup();
        $svnbackup->backup();
    }
    
    $isDatabaseBackup = $opts->getOption('database');
    
    if(!empty($isDatabaseBackup)){
        $dbbackup = new DatabaseBackup();
        $dbbackup->backup();
    }
   
    
    
}
catch(Exception $e){
    echo $e->getMessage(). "\n";
    echo $e->getTraceAsString();
}